package com.fly_fox.util;

import static org.apache.commons.lang3.StringUtils.isBlank;

/**
 * Created by ace on 2017/9/10.
 */
public class StringHelper {

    public static String getObjectValue(Object obj){
        return obj==null?"":obj.toString();
    }


    //  拷贝的mybatis-plus的驼峰转下划线
    public static String camelToUnderline(String param) {
        if (isBlank(param)) {
            return "";
        } else {
            int len = param.length();
            StringBuilder sb = new StringBuilder(len);

            for(int i = 0; i < len; ++i) {
                char c = param.charAt(i);
                if (Character.isUpperCase(c) && i > 0) {
                    sb.append('_');
                }

                sb.append(Character.toLowerCase(c));
            }

            return sb.toString();
        }
    }

    //  拷贝的mybatis-plus的下划线转驼峰
    public static String underlineToCamel(String param) {
        if (isBlank(param)) {
            return "";
        } else {
            String temp = param.toLowerCase();
            int len = temp.length();
            StringBuilder sb = new StringBuilder(len);

            for(int i = 0; i < len; ++i) {
                char c = temp.charAt(i);
                if (c == '_') {
                    ++i;
                    if (i < len) {
                        sb.append(Character.toUpperCase(temp.charAt(i)));
                    }
                } else {
                    sb.append(c);
                }
            }

            return sb.toString();
        }
    }

    /**
     * 首字母大写
     * fcl 是 Capital first-Letter 首字母大写的简写
     * @param name
     * @return
     */
    public static String cfLetter(String name) {
        //     name = name.substring(0, 1).toUpperCase() + name.substring(1);
        //     return  name;
        char[] cs=name.toCharArray();
        cs[0]-=32;
        return String.valueOf(cs);

    }

    /**
     * 首字母大写
     * fcl 是 lower first-Letter 首字母小写的简写
     * @param name
     * @return
     */
    public static String lfLetter(String name) {
        //     name = name.substring(0, 1).toUpperCase() + name.substring(1);
        //     return  name;
        char[] cs=name.toCharArray();
        cs[0]+=32;
        return String.valueOf(cs);

    }

    public static void main(String[] args) {
        String str="AsfDasdfAsdfa";
        System.out.println(camelToUnderline(str));
    }

}
